package cn.calm.commons.service.defaultimpl;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import cn.calm.commons.dao.QueryConditionBuilder;
import cn.calm.commons.entity.BaseEntity;

public class EqualQueryConditionBuilder<T extends BaseEntity> implements
		QueryConditionBuilder<T> {
	private String property;
	private Object value;

	public EqualQueryConditionBuilder(String property, Object value) {
		this.property = property;
		this.value = value;
	}

	@Override
	public void query(CriteriaBuilder r, CriteriaQuery<?> query,
			Root<? extends BaseEntity> root) {
		query.where(r.equal(root.get(property), value));
	}
}
